﻿using Power.Models;
using Power.View.Report;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace Power.ViewModel.Report
{
    /// <summary>
    /// 维护管道表
    /// </summary>
    public class MaintenanceSectionTableViewModel : ReportTableBase
    {
        public DefendTableData Data { get; set; }
        private MaintenanceSectionTable model;
        public MaintenanceSectionTableViewModel(MaintenanceSectionTable model)
        {
            this.model = model;
            Data = new DefendTableData()
            {

                MaintainLevel1 = new DefendTableBase() { PipeSecsSugRp = "1", WellNameSecsRp = "1" },
                MaintainLevel2 = new DefendTableBase() { PipeSecsSugRp = "1", WellNameSecsRp = "1" },
                MaintainLevel3 = new DefendTableBase() { PipeSecsSugRp = "1", WellNameSecsRp = "1" },
                MaintainLevel4 = new DefendTableBase() { PipeSecsSugRp = "1", WellNameSecsRp = "1" },

                RepairLevel1 = new DefendTableBase() { PipeSecsSugRp = "1", WellNameSecsRp = "1" },
                RepairLevel2 = new DefendTableBase() { PipeSecsSugRp = "1", WellNameSecsRp = "1" },
                RepairLevel3 = new DefendTableBase() { PipeSecsSugRp = "1", WellNameSecsRp = "1" },
                RepairLevel4 = new DefendTableBase() { PipeSecsSugRp = "1", WellNameSecsRp = "1" }
            };

            Init();
        }


        public void Init()
        {
            var color1 = new SolidColorBrush(Color.FromRgb(0, 0, 255));
            var color2 = new SolidColorBrush(Color.FromRgb(255, 255, 0));
            var color3 = new SolidColorBrush(Color.FromRgb(255, 102, 0));
            var color4 = new SolidColorBrush(Color.FromRgb(255, 0, 0));
            Row = 11;
            Column = 6;
            var table = this.model.table;

            for (int i = 0; i < Row; i++)
            {
                table.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(50) });

            }
            for (int i = 0; i < Column; i++)
            {
                if (i == 2)
                {
                    table.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(500) });
                }
                else if (i == 5)
                {
                    table.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(300) });

                }
                else
                {
                    table.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(100) });
                }
                
            }

            for (int i = 0; i < Row; i++)
            {
                for (int j = 0; j < Column; j++)
                {
                    DrawColumnSpanCell(table, i, j, "维护管段表", Column, 0, 0);


                    DrawRowSpanCell(table, i, j, "维护类型", 2, 1, 0);
                    DrawRowSpanCell(table, i, j, "维护等级", 2, 1, 1);
                    DrawRowSpanCell(table, i, j, "维护管段", 2, 1, 2);
                    DrawRowSpanCell(table, i, j, "管段数量", 2, 1, 3);

                    DrawCell(table, i, j, "管段占比", 1, 4);
                    DrawCell(table, i, j, "%", 2, 4);

                    DrawRowSpanCell(table, i, j, "维护建议", 2, 1, 5);

                    DrawRowSpanCell(table, i, j, "修复", 4, 3, 0);
                    DrawRowSpanCell(table, i, j, "养护", 4, 7, 0);

                    
                    DrawCell(table, i, j, "I", 3, 1, color1);
                    DrawCell(table, i, j, "II", 4, 1, color2);
                    DrawCell(table, i, j, "III", 5, 1, color3);
                    DrawCell(table, i, j, "IV", 6, 1, color4);

                    DrawCell(table, i, j, "I", 7, 1, color1);
                    DrawCell(table, i, j, "II", 8, 1, color2);
                    DrawCell(table, i, j, "III", 9, 1, color3);
                    DrawCell(table, i, j, "IV", 10, 1, color4);

                    var rowIndex = 3;
                    var columnIndex = 2;
                    //维护管段
                    DrawCell(table, i, j, Data.RepairLevel1.WellNameSecsRp, rowIndex++, columnIndex);
                    DrawCell(table, i, j, Data.RepairLevel2.WellNameSecsRp, rowIndex++, columnIndex);
                    DrawCell(table, i, j, Data.RepairLevel3.WellNameSecsRp, rowIndex++, columnIndex);
                    DrawCell(table, i, j, Data.RepairLevel4.WellNameSecsRp, rowIndex++, columnIndex);

                    DrawCell(table, i, j, Data.MaintainLevel1.WellNameSecsRp, rowIndex++, columnIndex);
                    DrawCell(table, i, j, Data.MaintainLevel2.WellNameSecsRp, rowIndex++, columnIndex);
                    DrawCell(table, i, j, Data.MaintainLevel3.WellNameSecsRp, rowIndex++, columnIndex);
                    DrawCell(table, i, j, Data.MaintainLevel4.WellNameSecsRp, rowIndex++, columnIndex);

                    //管段数量
                    rowIndex = 3;
                    columnIndex++;
                    DrawCell(table, i, j, Data.RepairLevel1.PipeSecsNumRp.ToString(), rowIndex++, columnIndex);
                    DrawCell(table, i, j, Data.RepairLevel2.PipeSecsNumRp.ToString(), rowIndex++, columnIndex);
                    DrawCell(table, i, j, Data.RepairLevel3.PipeSecsNumRp.ToString(), rowIndex++, columnIndex);
                    DrawCell(table, i, j, Data.RepairLevel4.PipeSecsNumRp.ToString(), rowIndex++, columnIndex);

                    DrawCell(table, i, j, Data.MaintainLevel1.PipeSecsNumRp.ToString(), rowIndex++, columnIndex);
                    DrawCell(table, i, j, Data.MaintainLevel2.PipeSecsNumRp.ToString(), rowIndex++, columnIndex);
                    DrawCell(table, i, j, Data.MaintainLevel3.PipeSecsNumRp.ToString(), rowIndex++, columnIndex);
                    DrawCell(table, i, j, Data.MaintainLevel4.PipeSecsNumRp.ToString(), rowIndex++, columnIndex);



                    //管段占比
                    rowIndex = 3;
                    columnIndex++;
                    DrawCell(table, i, j, Data.RepairLevel1.PipeSecsRateRp.ToString(), rowIndex++, columnIndex);
                    DrawCell(table, i, j, Data.RepairLevel2.PipeSecsRateRp.ToString(), rowIndex++, columnIndex);
                    DrawCell(table, i, j, Data.RepairLevel3.PipeSecsRateRp.ToString(), rowIndex++, columnIndex);
                    DrawCell(table, i, j, Data.RepairLevel4.PipeSecsRateRp.ToString(), rowIndex++, columnIndex);

                    DrawCell(table, i, j, Data.MaintainLevel1.PipeSecsRateRp.ToString(), rowIndex++, columnIndex);
                    DrawCell(table, i, j, Data.MaintainLevel2.PipeSecsRateRp.ToString(), rowIndex++, columnIndex);
                    DrawCell(table, i, j, Data.MaintainLevel3.PipeSecsRateRp.ToString(), rowIndex++, columnIndex);
                    DrawCell(table, i, j, Data.MaintainLevel4.PipeSecsRateRp.ToString(), rowIndex++, columnIndex);

                    //维护建议
                    rowIndex = 3;
                    columnIndex++;
                    DrawCell(table, i, j, Data.RepairLevel1.PipeSecsSugRp.ToString(), rowIndex++, columnIndex);
                    DrawCell(table, i, j, Data.RepairLevel2.PipeSecsSugRp.ToString(), rowIndex++, columnIndex);
                    DrawCell(table, i, j, Data.RepairLevel3.PipeSecsSugRp.ToString(), rowIndex++, columnIndex);
                    DrawCell(table, i, j, Data.RepairLevel4.PipeSecsSugRp.ToString(), rowIndex++, columnIndex);

                    DrawCell(table, i, j, Data.MaintainLevel1.PipeSecsSugRp.ToString(), rowIndex++, columnIndex);
                    DrawCell(table, i, j, Data.MaintainLevel2.PipeSecsSugRp.ToString(), rowIndex++, columnIndex);
                    DrawCell(table, i, j, Data.MaintainLevel3.PipeSecsSugRp.ToString(), rowIndex++, columnIndex);
                    DrawCell(table, i, j, Data.MaintainLevel4.PipeSecsSugRp.ToString(), rowIndex++, columnIndex);
                }
            }
            
            //补边框
            DrawBorder(table);
        }
    }
}
